package com.mediacloud.app.newsmodule.view.share

import android.app.Activity
import android.content.Context
import android.content.res.Configuration
import android.graphics.Bitmap
import com.mediacloud.app.model.news.ArticleItem
import com.mediacloud.app.share.model.ShareGridItem
import com.mediacloud.app.share.view.SharePopGridWindow

class PosterSharePopWrapper(var context: Context, var shareType: Int = IPosterSharePop.TYPE_NORMAL) : IPosterSharePop {
    var articleItem: ArticleItem? = null
    val posterShare: IPosterSharePop
    var posterShareH: IPosterSharePop? = null


    init {
        when (shareType) {
            IPosterSharePop.TYPE_NORMAL -> {
                posterShare = PosterSharePop1(context)
                posterShareH = PosterSharePop1h(context)
            }
            else -> {
                posterShare = PosterSharePop2(context)
                posterShareH = PosterSharePop1h(context)
            }
        }
    }

    override fun isPosterShareMode(): Boolean {
        return posterShare.isPosterShareMode()
    }

    override fun setPosterShareMode(posterMode: Boolean) {
        posterShare.setPosterShareMode(posterMode)
    }

    override fun isShowing(): Boolean {
        return posterShare.isShowing()
    }

    override fun setShareGridAdaptorData(data: List<ShareGridItem>?) {
        posterShare.setShareGridAdaptorData(data)

        posterShareH?.setShareGridAdaptorData(data)
    }

    override fun setFuncGridAdaptorData(data: List<ShareGridItem>?) {
        posterShare.setFuncGridAdaptorData(data)
        posterShareH?.setFuncGridAdaptorData(data)
    }

    override fun setonFuncItemClick(listener: SharePopGridWindow.OnGridItemClickListener) {
        posterShare.setonFuncItemClick(listener)
        posterShareH?.setonFuncItemClick(listener)
    }


    override fun show(view: Activity) {
        var isLand = false
        try {
            val configuration = view.resources.configuration;
            if (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
                isLand = true
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }


        if (isLand) {
            posterShareH?.show(view)
        } else {
            posterShare.show(view)
        }
    }

    override fun dismiss() {
        posterShareH?.dismiss()
        posterShare.dismiss()
    }

    override fun updateData(article: ArticleItem,bitmap: Bitmap?) {
        posterShare.updateData(article,bitmap)
    }

    override fun saveImage() {
        posterShare.saveImage()
    }

    override fun shareImage(share_media: Int) {
        posterShare.shareImage(share_media)
    }

    override fun setClickDismiss(boolean: Boolean) {
        posterShare.setClickDismiss(boolean)

    }
}